/*
 * First attempt at making a static plotter using Qt.  Function will take a
 * standard file of just y points.  Figuring out the maximum and minimum and
 * plot the data accordlying
 */

// Standard includes
#include <iostream>
#include <fstream>
#include <vector>
// QT Includes
#include <QApplication>
#include <QDesktopWidget>
#include <QWidget>
// Project Includes
#include "mainwindow.h"

int main(int argc, char *argv[]) {
  
  ifstream plotFile;
  vector<float> data(10240);
  float temp;
  int dx;
  // Parse the input
  if (argc <= 1) {
		cout << "A file must be specified to plot" << endl;
        return -1;
  } else {
	// Try to open the file for reading
    plotFile.open( argv[1] , ios::in | ios::binary);
	// Check to see if it opened
		if ( !plotFile.is_open() ) {
	  	cout << "Unable to open file (" << argv[1] << ")\n";
	  	return -2;
		}
  }
  // Read the file into a vector
  plotFile.seekg( 512, ios::beg );
  for(dx = 0; dx < data.size(); dx++) {
      plotFile.read( (char *)&temp, sizeof(float));
      data.at(dx) = temp;
  }
  // Create a new appliation
  QApplication plotApp(argc, argv);
  //qApp->setStyleSheet("* {color: white; background-color: black}");
  //QWidget plotWindow;
  //twodplot plotWindow;
  MainWindow window( argv[1], data );
  // Center the window on the screen ( 1 if there is multiple desktops)
  //plotWindow.setWindowTitle("QT Plot");
  // Draw the plot frame
  // Draw the data inside the plot frame
  // Center the window on the screen
  //center( plotWindow );
  // Display the window on the screen
  window.show();

  data.resize( 100, .5 );
  window.plotFrame->data = data;

  
  // Close the file before leaving
  plotFile.close();
  if ( plotFile.is_open() ) {
	cout << "Unable to close the file (" << argv[1] << ")\n";
  }
  
  return plotApp.exec();
}
